package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 普通请求参数接收
 * @author stone
 * @date 2022/11/15 21:19
 */
@RestController
@RequestMapping("user")
public class UserController {

    //localhost:8080/user/register1?username=songge&password=niupi&age=40
    @RequestMapping("register1")
    public BaseRespVo register1(String username,String password,Integer age) {
        return BaseRespVo.ok(username + "-->" + password + "-->" + age);
    }
    //localhost:8080/user/register2?username=songge&password=niupi
    @RequestMapping("register2")
    public BaseRespVo register2(String username,String password,int age) {
        return BaseRespVo.ok();
    }
    //localhost:8080/user/register3?username=songge&password=niupi&age=30&birthday=2022/06/21
    @RequestMapping("register3")
    public BaseRespVo register3(String username,String password,Integer age,
                                Date birthday) {
        //Date date = new SimpleDateFormat("yyyy/MM/dd").parse(birthday);
        return BaseRespVo.ok(birthday);
    }

    // 提供的参数值并不是yyyy/MM/dd ，并不是默认的日期格式
    // 我们参数的日期格式 yyyy-MM-dd
    //localhost:8080/user/register4?username=songge&password=niupi&age=30&birthday=2022-06-21
    @RequestMapping("register4")
    public BaseRespVo register4(String username,String password,Integer age,
                                @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday) {

        return BaseRespVo.ok(birthday);
    }
    // 请求参数中，使用了相同key，我们就可以使用数组来接收
    //localhost:8080/user/register5?username=songge&password=niupi&age=30
    // &hobbies=sing&hobbies=dance&hobbies=rap
    // &ids=1&ids=2&ids=3
    @RequestMapping("register5")
    public BaseRespVo register5(String username,String password,Integer age,
                                String[] hobbies,Integer[] ids) {
        return BaseRespVo.ok();
    }
    //localhost:8080/user/register6?username=songge&password=niupi&age=30
    // &hobbies=sing&hobbies=dance&hobbies=rap&ids=1&ids=2&ids=3
    // &birthday=2022-06-21
    @RequestMapping("register6")
    /*public BaseRespVo register6(String username,String password,Integer age,
                                String[] hobbies,Integer[] ids,
                                @DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday) {*/
    public BaseRespVo register6(User user){
        return BaseRespVo.ok();
    }
}
